package com.zte.stats.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zte.stats.dao.IStatsDeliveryDao;
import com.zte.stats.model.*;
import com.zte.stats.service.IStatsDeliveryService;
import com.zte.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StatsDeliveryServiceImpl implements IStatsDeliveryService {

    @Autowired
    private IStatsDeliveryDao iStatsDeliveryDao;

    @Override
    public PageModel<StatsWarehouse<StatsCkWarehouse>> queryWarehouseList(PageModel<StatsWarehouse<StatsCkWarehouse>> pageModel, StatsDeliveryCondition sdc) {
        int pageNum = pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 5 : pageModel.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<StatsWarehouse<StatsCkWarehouse>> statsWarehouses = iStatsDeliveryDao.queryWarehouse(sdc);
        PageInfo<StatsWarehouse<StatsCkWarehouse>> info = new PageInfo<StatsWarehouse<StatsCkWarehouse>>(statsWarehouses);
        pageModel.setPageNum(info.getPageNum());
        pageModel.setPageSize(info.getPageSize());
        pageModel.setTotalPage(info.getPages());
        pageModel.setTotalCount((int) info.getTotal());
        pageModel.setData(new ArrayList<StatsWarehouse<StatsCkWarehouse>>(info.getList()));
        return pageModel;
    }

    @Override
    public PageModel<StatsCkWarehouse> queryCKWarehouseList(PageModel<StatsCkWarehouse> pageModel, StatsDeliveryCondition sdc) {
        int pageNum = pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 5 : pageModel.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<StatsCkWarehouse> statsCkWarehouses = iStatsDeliveryDao.queryCKWarehouse(sdc);
        PageInfo<StatsCkWarehouse> info = new PageInfo<StatsCkWarehouse>(statsCkWarehouses);
        pageModel.setPageNum(info.getPageNum());
        pageModel.setPageSize(info.getPageSize());
        pageModel.setTotalPage(info.getPages());
        pageModel.setTotalCount((int) info.getTotal());
        pageModel.setData(new ArrayList<StatsCkWarehouse>(info.getList()));
        return pageModel;
    }

}
